import psycopg

connection_config = {'user':'postgres',
                     'password':'123456',
                     'host':'localhost',
                     'port':'5432'}

class PsqlManager:
    """
    简单封装下接口进行查询
    """
    def __init__(self,connection_config):
        self.config = connection_config

    def execute(self, query):
        with psycopg.connect(**self.config).cursor() as cursor:
            cursor.execute(query)
            fetchall = cursor.fetchall()
            print(fetchall)
        return fetchall

if __name__ == '__main__':
    psql = PsqlManager(connection_config)
    psql.execute('select version();')